import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    name: '',
    list: []
  },
  mutations: {
    names(state, a) {//添加用户名
      if (a == true) {
        state.name = ''
        return false
      }
      state.name = a
    },

    listx(state, a) {//添加购物车数据
      state.list = a
    },
    xz(state, a) {//更新购物车数据
      state.list = a
    }
  },
  actions: {

  },
  getters: {
    zj(state, a) {
      let length = state.list.length
      let zf = 0
      let sl = 0
      state.list.map((a) => {
        if (a.check == true) {
          zf += a.num * a.price
          sl++
        }
      })
      return { length, zf, sl }
    }
  }
})
